package com.mop.springcloud.corebase.controller;

import com.mop.springcloud.corebase.MopApplicationInitializer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;

/**
 * Class Name: MopBuildinController
 * Create Date: 18-3-16 上午9:56
 * Creator: Chim·Zigui
 * Version: v1.0
 * Updater:
 * Date Time:
 * Description:
 * <p>
 * 猫扑 mop-spring-boot-starter 的內建控制器，用于查询 服务/app 的信息
 */
@RestController
@RequestMapping(value = "/mop/buildin/admin/core")
public class MopBuildInController {

    @Autowired
    private MopApplicationInitializer initializer = null;

    /**
     * 获得服务的启动信息
     */
    @RequestMapping(value = "/info")
    public void info(HttpServletResponse response) {
        response.setContentType("text/plain");
        PrintWriter writer = null;
        try {
            writer = response.getWriter();
            writer.write(initializer.getStarterInfoPrintData());
            writer.write("\n\n " + new Date());
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (writer != null) {
                writer.flush();
                writer.close();
            }
        }
    }
}
